package com.eascs.overdue.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.eascs.admin.o2o.internal.util.StatusContexts;
import com.eascs.admin.o2o.loan.entity.O2oLoanUserEntity;
import com.eascs.admin.o2o.loan.entity.O2oLoanapplyEntity;
import com.eascs.admin.o2o.loan.service.O2oLoanapplyService;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.StringUtil;
import com.eascs.overdue.dao.O2oOverdueDao;
import com.eascs.overdue.dao.O2oOverdueReportDao;
import com.eascs.overdue.entity.O2oOverdueFormEntity;
import com.eascs.overdue.entity.O2oOverdueReport;
import com.eascs.overdue.entity.O2oOverdueReportInterim;
import com.eascs.overdue.entity.O2oStatus;
import com.eascs.pay.dao.O2oPayDao;

@Service
public class O2oOverdueReportService {
	@Autowired
	private O2oOverdueReportDao o2oOverdueReportDao;
	
	@Autowired
	private O2oOverdueDao o2oOverdueDao;
	@Autowired
	private O2oLoanapplyService o2oLoanapplyService;
	
	@Autowired
	private O2oPayDao o2oPayDao;
	
	
	private static Logger log = LoggerFactory.getLogger(O2oOverdueReportService.class);
	
	@Transactional("o2oTransactionManager")
	public String addList(List<List<Object>>  result){ //先将导入的数据放入临时表
		//循环插入
		//1:先将数据库中的数据标示全部置为N
		 //允许单据编号一样，但是状态不一样的重新插入（改为全量，插入前将数据库中之前所有的数据状态都标志为N）
		O2oOverdueReportInterim o = new O2oOverdueReportInterim();
		o.setIsnew("Y");
	    List<O2oOverdueReportInterim>  vo = findO2oOverdueReportList(o);
	     if(vo!=null&&vo.size()!=0){
	    	 for(int j= 0; j<vo.size();j++){
	    		 o = vo.get(j);
	    		 o.setIsnew("N");
	    		 updateEntityById(o);//根据编号还有isnew 这个状态去查询这个类
	    	 }
	     }
	     Date creteDate = new Date();
//	     String creteDateString = DateUtils.formateStandDateTime(creteDate);
		for (int i = 0; i < result.size(); i++) {
			//如果贷款单号是o2o开头的那就老系统
			//新系统插入数据
			@SuppressWarnings("unused")
			String rows = String.valueOf(i + 1);
			@SuppressWarnings({ "unchecked", "rawtypes" })
			List<Object> list = (List) result.get(i);
			String loanapplyno = list.get(0).toString().trim();   //贷款申请编号
			O2oOverdueReportInterim overdueReportPO = new O2oOverdueReportInterim ();
			
			O2oLoanapplyEntity apply = new O2oLoanapplyEntity();
			 //主借贷表 apply
			apply = o2oLoanapplyService.fingByBillCode(loanapplyno.trim());
			 if(apply==null){
				 log.error("单据号为:"+loanapplyno +"的单不存在！");
				 throw new RuntimeException("单据号为:"+loanapplyno +"的单不存在！");
			 }
			
			 //借款信息
			 O2oLoanUserEntity loaner = o2oLoanapplyService.findLoanUserEntity(apply.getLoanapplyNo(),apply.getLoanId());
			 if(loaner==null){
				 log.error("单据号为:"+loanapplyno +"的借款信息不存在！");
				 throw new RuntimeException("单据号为:"+loanapplyno +"的借款信息不存在！");
			 }
			 //检查贷款单号和借款人姓名是否一致，不一致的就不让通过
			 String loanName = list.get(1).toString().trim();   //借款人姓名
			 if(!loanName.equals(loaner.getUserFullName())){
				 log.error("单据号为:"+loanapplyno +"的借款与上传表单中的借款人名称不一致请检查");
				 throw new RuntimeException("单据号为:"+loanapplyno +"的借款与上传表单中的借款人名称不一致请检查！");
			 }
			 
			 //系统关联数据(其中省区如何关联还有待考证)  报表中会有省区
			 overdueReportPO.setLtd(apply.getLtd().toString());
			 overdueReportPO.setLoanapplyno(apply.getLoanapplyNo());
			 overdueReportPO.setIdcard(loaner.getDocumentNo());
			 //放款银行跟放款时间有可能没有
			 overdueReportPO.setBankrefundcode(apply.getBankLoanName());
			 overdueReportPO.setLoaddate(apply.getPaymentTime());  //放款时间
			 if(apply.getPaymentTime()!=null){
				 overdueReportPO.setMaturitydate(apply.getEndBankDate());  //到期时间 = 放款时间 + 借款期限 
			 }else{
				 log.error("单据号为:"+loanapplyno +"的单，不存在放款日期请核实.");
				 throw new RuntimeException("单据号为:"+loanapplyno +"的单，不存在放款日期请核实.");
			 }
			 overdueReportPO.setLoanamount(apply.getLoanaMount());
			 overdueReportPO.setBillcode(apply.getBillCode());
			 // 录入数据：
			// 录入数据：
			 overdueReportPO.setLoanername(list.get(1).toString());
			 overdueReportPO.setDefaultamount((BigDecimal) list.get(2));   //拖欠总额 
			 overdueReportPO.setDefaultcapital((BigDecimal)list.get(3)); //逾期本金
			 overdueReportPO.setDefaultinterest((BigDecimal)list.get(4));//逾期利息 
			 overdueReportPO.setPenaltyinterest((BigDecimal)list.get(5));//罚息合计
			 overdueReportPO.setDefaultdatenum((BigDecimal)list.get(6));//逾期天数
			 overdueReportPO.setIsdel("N");
			 overdueReportPO.setStatus(list.get(7).toString().split("-")[0]);   //当前处置状态 
			 overdueReportPO.setDisposalamoun((BigDecimal)list.get(8)); //处置金额
			 overdueReportPO.setIsnew("Y");//是否是最新的 
			 //overdueReportPO.setDisposalDate(com.eabiroom.utils.DateUtils.getFormatDate(list.get(9),"yyyy-MM-dd")); //处置时间 
			 overdueReportPO.setDisposaldate((Date)list.get(9));//处置时间
			 overdueReportPO.setTimeframe((Date)list.get(10));//统计时间
			 if(list.get(11)!=null){
				 overdueReportPO.setRemarks((String)list.get(11)); //备注
			 }
			 overdueReportPO.setCreatetime(creteDate); //创建日期统一用刚刚进入这个方法的时间
			/* 20170110
			 overdueReportPO.setLoanername(list.get(1).toString());
			 overdueReportPO.setDefaultamount((BigDecimal) list.get(2));   //拖欠总额 
			 overdueReportPO.setIsdel("N");
			 overdueReportPO.setStatus(list.get(3).toString().split("-")[0]);   //当前处置状态 
			 overdueReportPO.setIsnew("Y");//是否是最新的 
			 //overdueReportPO.setDisposalDate(com.eabiroom.utils.DateUtils.getFormatDate(list.get(9),"yyyy-MM-dd")); //处置时间 
			 overdueReportPO.setDisposaldate((Date)list.get(4)); //统计日期
			 overdueReportPO.setCreatetime(creteDate); //创建日期统一用刚刚进入这个方法的时间
			 if(list.get(5)!=null){
				 overdueReportPO.setRemarks((String)list.get(5)); //备注
			 }*/
			 saveEntityById(overdueReportPO);
	  }
		return "success";
	}
	
	/**
	 * 将临时表中的数据做初步验证之后，修改主表状态，然后更新正式表
	 * @return
	 */
	@Transactional("o2oTransactionManager")
	public String addDealInterim(){ 
		//初步验证excel中数据的正确性
		List<Object[]>  checkBankDisDate = checkBankDisDate();
		for(int i = 0 ;i<checkBankDisDate.size();i++ ){
			if((long)checkBankDisDate.get(i)[1]>1){
				log.error("放款银行为"+(String)checkBankDisDate.get(i)[0]+",处置时间存在"+(long)checkBankDisDate.get(i)[1]+"个不同的值");
				throw new RuntimeException("放款银行为"+(String)checkBankDisDate.get(i)[0]+",处置时间存在"+(long)checkBankDisDate.get(i)[1]+"个不同的值");
			}
		}
		//将bank对应的处理日期封装到map中
		//第一步    ：  有放款状态的更新成已放款状态(接力贷，分期贷的不初始化)
		 	dealByloanFlg();
		 
		// 第二步  ： 分银行和到期日小于等于处理日期的数据，先将状态全部重置为已结清(接力贷，分期贷的不初始化)
		/* List<Object[]> bankDisDate = getBankDisDate();
		 Map<String,String> bankDisDateMap=new HashMap<String,String>();
		 for(int i = 0 ;i<bankDisDate.size();i++ ){
			 bankDisDateMap.put((String)bankDisDate.get(i)[0],DateUtils.formateStandDateTime((Date)bankDisDate.get(i)[1]));
			 if(((String)bankDisDate.get(i)[0]).equals(StatusContexts.O2O_BANKTYPE_BC)){//只有中行的去做处理
				 dealByBankAndEndBankDate( DateUtils.formateStandDateTime((Date)bankDisDate.get(i)[1]),(String)bankDisDate.get(i)[0]);
			 }
			}*/
		 
		 // 第三步 ： excel 没有导入的银行，按照excel中逾期的最大的统计日期与到期日作比较，如果到期日<=excel中逾期的最大的统计日期 ,将状态改成已结清 (接力贷，分期贷的不初始化)
		 //20170401 只管中行数据其他银行不做处理 loan-11287
		/* String maxBankDisDate = null;
		 List<Object[]> s =  getMaxBankDisDate();
		 if(s!=null&&s.size()>0){
			 maxBankDisDate = DateUtils.formateStandDate((Date)s.get(0)[0]);
		 }
		 
		 if(StringUtil.isNotBlank(maxBankDisDate)){
			 //如果到期日<=excel中逾期的最大的统计日期 ,将状态改成已结清
			 dealMaxBankDisDate(maxBankDisDate);
		 }*/
		 
		//第四步  ：  按照导入的数据 更新主表状态
		 List<O2oOverdueReport> impList =  getImpBankDisDate();
		 for(int i = 0; i<impList.size();i++){
			 O2oOverdueReport over = impList.get(i);
			 if(over.getStatus().equals(StatusContexts.OVERDUE_LXYQ)||over.getStatus().equals(StatusContexts.OVERDUE_BJYQ)){
				 dealByImpData(over.getBillcode(),StatusContexts.OVERDUE_YQ);
			 }
//			 else{
//				 dealByImpData(over.getBillcode(),StatusContexts.OVERDUE_DC); 
//			 }
		 }
		 /*----start   cxw  loan-11489 齐鲁、江西及郑州银行代偿、逾期处理
		  * http://tick.o2ojr.eascs.com/ticket/view/loan-11489
		  */
//		List<O2oOverdueReport> overdueReports = getImpBankData();
//		if (null != overdueReports && overdueReports.size() > 0) {
//			for (int i = 0; i < overdueReports.size(); i++) {
//				O2oOverdueReport over = overdueReports.get(i);
//				dealByImpData(over.getBillcode(), StatusContexts.O2O_FK_END);
//				dealByImpData(over.getBillcode(), StatusContexts.OVERDUE_YQ);
//			}
//		}
		//----end
		//第五步 ： 如果导入的列表中存在一个单有多种状态其中有代偿的直接改成代偿状态
		 //dealDoubble();
		//第五步：从临时表插入到正式表中
		 //int count =  
				 interimToFormal();
		return "success";
	}
	
	public List<O2oOverdueReportInterim> findO2oOverdueReportList(O2oOverdueReportInterim o2oOverdueReport) {
		StringBuffer sql= new StringBuffer("select * from o2o_overdue_report_interim od where 1 = 1 ");
		List<Object> listParams = new ArrayList<Object>();
		
		if(o2oOverdueReport!=null){
			if(StringUtil.isNotBlank(o2oOverdueReport.getIsnew())){
				sql.append(" and od.isnew = ? ");
				listParams.add(o2oOverdueReport.getIsnew());
			}
		}
		return o2oPayDao.findEntitys(sql.toString(), O2oOverdueReportInterim.class,listParams);
	}
	
	public int updateEntityById(O2oOverdueReportInterim o2oOverdueRepor) {
		return o2oPayDao.updateById(o2oOverdueRepor);
	}
	
	public int saveEntityById(O2oOverdueReportInterim o2oOverdueReport) {
		return o2oPayDao.insert(o2oOverdueReport);
	}
	/**
	 * 校验逾期报表是否已结清
	 * @param code
	 * @return
	 */
	public List<O2oStatus> findBillCode(String code){
		return o2oOverdueReportDao.findCode(code);
	}

	/**
	 * @Description:
	 *               <p>
	 *               查询  夫妻双方的逾期和代偿信息
	 *               </p>
	 * @author CXW
	 * @date 2016年12月28日 下午1:33:46
	 * @version V1.0
	 */
	public PageResult<Object[]> findOverReport(O2oOverdueFormEntity entity) {
		SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, entity.getPageSize(), entity.getPageIndex());
		StringBuffer querySql = new StringBuffer();
		querySql.append(" SELECT OVERDUE.BILLCODE,U.CUSTOMER_NAME AS LOAN_NAME, ITEM.ITEM_NAME AS BANK_LOAN_NAME,");
		querySql.append(" LOAN.LOAN_AMOUNT AS BANK_AMOUNT ,DATE_FORMAT(L.END_BANK_DATE, '%Y-%m-%d') AS END_BANK_DATE, OVERDUE.STATUS,");
		//querySql.append(" DATE_FORMAT(DISPOSALDATE,'%Y-%m-%m') AS DISPOSALDATE,  DEFAULTAMOUNT, ");
		querySql.append(" DATE_FORMAT(DISPOSALDATE,'%Y-%m-%d') AS DISPOSALDATE,");
		//querySql.append(" DEFAULTCAPITAL,  DEFAULTINTEREST,PENALTYINTEREST,DISPOSALAMOUN, ");
		querySql.append(" DISPOSALAMOUN, ");
		querySql.append(" DATE_FORMAT(TIMEFRAME,'%Y-%m-%d') AS TIMEFRAME ,L.wf_type");
		querySql.append(" FROM (");
		querySql.append(" SELECT * from (");
		querySql.append(" SELECT OVERDUE.BILLCODE,OVERDUE.STATUS,OVERDUE.DISPOSALDATE,OVERDUE.DISPOSALAMOUN,OVERDUE.TIMEFRAME,");
		querySql.append(" OVERDUE.ISNEW,OVERDUE.ISDEL");
		querySql.append(" from O2O_OVERDUE_REPORT OVERDUE");
		querySql.append(" UNION ");
		querySql.append(" SELECT a.bill_code_ea as BILLCODE,'3' as STATUS,a.pay_date as DISPOSALDATE,a.pay_amount as DISPOSALAMOUN,");
		querySql.append(" null as TIMEFRAME,'Y' AS ISNEW,is_del AS ISDEL");
		querySql.append(" from o2o_ea_loan_data a  where a.is_del='N' and a.pay_type='DF'");
		querySql.append(" ) t group by BILLCODE,STATUS,DISPOSALDATE,DISPOSALAMOUN,ISNEW,ISDEL");
		querySql.append(" ) OVERDUE");
		querySql.append(" LEFT JOIN O2O_LOANAPPLY L ON OVERDUE.BILLCODE = L.BILL_CODE");
		querySql.append(" LEFT JOIN O2O_LOAN_USER U ON L.LOAN_ID = U.LOAN_ID AND U.SPOUSE_ID IS NULL");
		querySql.append(" LEFT JOIN PUB_DDITEM ITEM  ON ITEM.DD_NO = 10340 AND ITEM.ITEM_CODE = L.BANK_LOAN_NAME");
		querySql.append(" LEFT JOIN O2O_BANK_LOAN_DATA LOAN ON L.BILL_CODE=LOAN.BILL_CODE ");
		querySql.append(" WHERE /**DATA_PERMISSION(L.LTD)**/ L.ISLOCK = 'N' AND L.LOANAPPLY_NO = U.LOANAPPLY_NO");
		querySql.append(" AND OVERDUE.ISNEW = 'Y' AND OVERDUE.ISDEL = 'N' AND U.DOCUMENT_NO IN (?,?)");
		sqlPageQuery.addParam(entity.getIdCard());
		sqlPageQuery.addParam(entity.getSpouseIdCard());
		querySql.append(" ORDER BY l.END_BANK_DATE DESC,CONVERT(U.CUSTOMER_NAME using GBK) ASC");
		sqlPageQuery.setQuerySql(querySql.toString());
		return o2oOverdueDao.findDataWithPage(sqlPageQuery);
	}
	
	
	/**
	 * 获取导入的数据列表
	 * @param o2oOverdueReport
	 * @return
	 */
	public List<O2oOverdueReport> getImpBankDisDate() {
		StringBuffer sql= new StringBuffer(" select * from o2o_overdue_report_interim where isnew = 'Y' ");
		return o2oPayDao.findEntitys(sql.toString(), O2oOverdueReport.class);
	}
	
	/**
	 * @Description:
	 *               <p>
	 *               获取导入的数据，银行为中行、江西银行，齐鲁银行、郑州银行的数据
	 *               </p>
	 * @author CXW
	 * @date 2017年8月10日 下午2:23:16
	 * @version V1.0
	 */
	public List<O2oOverdueReport> getImpBankData() {
		StringBuffer sql= new StringBuffer(" select * from o2o_overdue_report_interim where isnew = 'Y' and bankrefundcode in ('BC','QLB','JCB','ZZB')");
		return o2oPayDao.findEntitys(sql.toString(), O2oOverdueReport.class);
	}
	
	/**
	 * 按银行获取统计日期
	 * @param 
	 * @return
	 */
	public List<Object[]> getBankDisDate() {
		/*StringBuffer sql= new StringBuffer(" select bankrefundcode,disposaldate,count(*) from o2o_overdue_report_interim where isnew = 'Y' and date_format(createtime,'%Y-%m-%d %T') = ? GROUP BY bankrefundcode,disposaldate ");
		return o2oPayDao.findObjectsList(sql.toString(),createTime);*/
		StringBuffer sql= new StringBuffer(" select bankrefundcode,timeframe,count(*) from o2o_overdue_report_interim where isnew = 'Y' and status in ('1','2')  GROUP BY bankrefundcode,timeframe ");
		return o2oPayDao.findObjectsList(sql.toString());
	}
	
	/**
	 * 获取逾期数据中的最大统计日期
	 * @param 
	 * @return
	 */
	public List<Object[]> getMaxBankDisDate() {
		StringBuffer sql= new StringBuffer(" select Max(timeframe) from o2o_overdue_report_interim where isnew = 'Y' and status in ('1','2') ");
		return o2oPayDao.findObjectsList(sql.toString());
	}
	
	/**
	 * 逾期没有包含的银行，按照最大的统计日更新数据
	 * @param 
	 * @return
	 */
	public int dealMaxBankDisDate(String maxDate) {
		StringBuffer sql= new StringBuffer(" update o2o_loanapply t  set wf_type = 'HN' where date_format(end_bank_date,'%Y-%m-%d') <= ? and t.loan_type not in ('EA','FQ') and Bank_Loan_Name not in ( " 
						+ " select bankrefundcode from o2o_overdue_report_interim where isnew = 'Y' and status in ('1','2') GROUP BY bankrefundcode ) ");
		return o2oPayDao.execute(sql.toString(),maxDate);
	}
	
	/**
	 * 检查每个银行导入的处理日期是否一致（直接在临时表中去检查,只取逾期数据的日期）
	 * @param o2oOverdueReport
	 * @return
	 */
	public List<Object[]> checkBankDisDate() {
		StringBuffer sql= new StringBuffer(" select bankrefundcode,count(*) from ( select bankrefundcode,timeframe,count(*) "
				+ "from o2o_overdue_report_interim where isnew = 'Y' and status in ('1','2')  GROUP BY bankrefundcode,timeframe )t GROUP BY bankrefundcode ");
		return o2oPayDao.findObjectsList(sql.toString());
	}

	/**
	 * 分银行和到期日小于等于处理日期的数据，先将状态全部重置为已结清
	 */
	public void dealByBankAndEndBankDate(String timeframe,String bankLoanName){
		StringBuffer sql= new StringBuffer(" update o2o_loanapply t,o2o_bank_loan_data op  set t.wf_type='HN',t.settle_date=end_bank_date  "
				+ " where t.bill_code = op.bill_code and date_format(end_bank_date,'%Y-%m-%d') <=? "
				+ " and loan_flg = 'Y' and  op.loan_bank = ? and t.loan_type not in ('EA','FQ') and  t.wf_type !='DC' ");
		o2oPayDao.execute(sql.toString(), timeframe,bankLoanName);
	}
	
	/**
	 * 根据导入的数据,更新主表的状态
	 */
	public void dealByImpData(String billCode,String banktype){
		StringBuffer sql= new StringBuffer(" update o2o_loanapply t set t.wf_type=?,t.settle_date=null where bill_code = ? AND t.wf_type = 'O' ");
		o2oPayDao.execute(sql.toString(),banktype,billCode);
	}
	
	/**
	 * 根据主表中有放款时间的更新成已放款(20170401目前只管中行的)
	 */
	public void dealByloanFlg() {
		StringBuffer sql = new StringBuffer();
		sql.append(" update o2o_loanapply t,o2o_bank_loan_data op set  t.wf_type='O'");
		sql.append(" where  t.bill_code = op.bill_code  and t.payment_time is not null");
		sql.append(" and t.loan_type not in ('EA','FQ') and  t.wf_type = 'YQ'");
		sql.append(" and t.bill_code not in (" + getEaLoanBillCode() + ")");
		log.info("import overdue Report update o2o_loanapply sql:【{}】", sql.toString());
		o2oPayDao.execute(sql.toString());
	}
	
	/**
	 * 从临时表插入到正式表中(先清空在插入)
	 */
	public int interimToFormal(){
		StringBuffer sqlbefore= new StringBuffer(" truncate table o2o_overdue_report  ");
		o2oPayDao.execute(sqlbefore.toString());
		StringBuffer sql= new StringBuffer(" insert into o2o_overdue_report select * from o2o_overdue_report_interim where ISNEW = 'Y' ");
		return o2oPayDao.execute(sql.toString());
	}
	//第四步 ： 如果导入的列表中存在一个单有两种状态的取代偿状态
	/**
	 * 如果导入的列表中存在一个单有两种状态的取代偿状态
	 */
	public int dealDoubble(){
		/*StringBuffer sqlbefore= new StringBuffer(" update o2o_loanapply  set wf_type = 'DC' where bill_code in ( " +
						" select billcode from o2o_overdue_report_interim GROUP BY billcode,status having count(*) = 1 and billcode in "+
						" (select billcode from o2o_overdue_report_interim where isnew = 'Y' GROUP BY billcode having count(*) > 1  ) )" );*/
		StringBuffer sqlbefore= new StringBuffer(" update o2o_loanapply  set wf_type = 'DC' where bill_code in ( " +
				" select billcode from o2o_overdue_report_interim where isnew = 'Y' and status in ('3','4') and billcode in "+
				" ( select billcode from o2o_overdue_report_interim where isnew = 'Y' GROUP BY billcode having count(*) > 1 ) )" );
		return o2oPayDao.execute(sqlbefore.toString());
	}
	
	/**
	 * @Description:
	 *               <p>
	 *               获取利息代偿未结清的贷款单，loan-12290 逾期报表导入-状态更新优化
	 *               </p>
	 * @author CXW
	 * @date 2017年9月18日 下午3:57:49
	 * @version V1.0
	 */
	public String getEaLoanBillCode() {
		String sql = "SELECT oeld.bill_code_ea from o2o_ea_loan_data oeld where oeld.loan_type='LXDC' ";
		sql += "and oeld.bill_code_ea not in (SELECT oels.bill_code from o2o_ea_loan_settle oels ";
		sql += "join o2o_ea_loan_data oeld on oels.loan_data_id = oeld.id where oeld.loan_type='LXDC' ";
		sql += "and oels.is_delete='N' and oels.flow_status='CLO' GROUP BY oels.bill_code) ";
		List<Object[]> billCodes = o2oOverdueDao.findObjectsList(sql);
		String resultBillCode = "";
		if (billCodes != null && billCodes.size() > 0) {
			StringBuffer stringBuffer = new StringBuffer();
			for (int i = 0; i < billCodes.size(); i++) {
				stringBuffer.append("'").append(billCodes.get(i)[0]).append("',");
			}
			resultBillCode = stringBuffer.substring(0, stringBuffer.length()-1);
		}
		return resultBillCode;
	}
}
